<?php
class StringUltil{

	public static function trimSlash($str){
		return str_replace(SLASH, STRING_EMPTY, $str);
	}
	public static function trimChar($str,$char){
		return str_replace($char, STRING_EMPTY, $str);
	}
	/**
	 * Replace {0},{1},... by parram in Array.
	 * @param String $template
	 * @param array $parram
	 */
	public static function format($template,array $parram){
		$i = 0;
		$output = $template;
		foreach ($parram as $value) {
			$key = '{'.$i.'}';
			$output = str_replace($key, $value, $output);
			$i++;
		}
		return $output;
	} 
	public static function encryptPassWord($password){
		return md5($password + strlen($password));
	}
	public static function trim($str){
		return trim($str," \t\r\n\0\x0B");
	}
	public static function formatNormalString($str){
		$str = StringUltil::trim($str);
		$skipchar = array(' ','`','~','!','@','#','$','%','^','&','*','(',')','-','+','[',']','{','}','.'
				,',','<','>','/','\\','?'
		);
		return str_replace($skipchar, '', $str);
	}
	public static function encodeHTML($str){
		if(!isset($str) || strlen($str) == 0) return "";
		//$str = str_replace('"', '\"', $str);
		return $str;
	}
	public static function isNullOrEmpty($val){
		return isset($val) || $val == "";
	} 
	public static function vnStrFilter($str){
		$unicode = array(
				'a'=>'á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ',
				'd'=>'đ',
				'e'=>'é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ',
				'i'=>'í|ì|ỉ|ĩ|ị',
				'o'=>'ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ',
				'u'=>'ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự',
				'y'=>'ý|ỳ|ỷ|ỹ|ỵ',
				'A'=>'Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ',
				'D'=>'Đ',
				'E'=>'É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ',
				'I'=>'Í|Ì|Ỉ|Ĩ|Ị',
				'O'=>'Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ',
				'U'=>'Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự',
				'Y'=>'Ý|Ỳ|Ỷ|Ỹ|Ỵ',
				'-'=>'?|--| |---|\'|"'
		);
		foreach($unicode as $nonUnicode=>$uni){
			$str = preg_replace("/($uni)/i", $nonUnicode, $str);
		}
// 		$str = str_replace("?"," ",$str);
// 		$str = str_replace("/","-",$str);
// 		$str = str_replace('"',"-",$str);
// 		$str = str_replace("'","-",$str);
// 		$str = str_replace("--","-",$str);
// 		$str = str_replace("---","-",$str);
// 		$str = str_replace("----","-",$str);
// 		$str = str_replace(" ","-",$str);
		$str = strtolower($str);
		return $str;
	}
}